# makfile configuration
NAME            = mode

OBJECTS         = mode_freq.o mode_station.o mode_vol.o menu.o stats.o simon.o

#should be 149, waiting for wsim
CPU             = msp430x149

DEPS	= ../control/ctrl_vol.o ../control/ctrl_freq.o
CTRL_DIR	= ../control/

# Includes necessaire pour les appels systemes
OSDIR		= ../os
RTOSDIR		= $(OSDIR)/OS/
PORTDIR         = $(OSDIR)/Ports/MSP430/F1611/GNU

INCDIRS		= -I$(OSDIR) -I$(PORTDIR) -I$(RTOSDIR)

# default flags for compilation
DEFAULT_FLAGS	= -mmcu=${CPU} $(INCDIRS) -Wall -g

#switch the compiler (for the internal make rules)
CC              = msp430-gcc
# use when building the entire program
CFLAGS          = ${DEFAULT_FLAGS}


.PHONY: all FORCE clean download download-jtag download-bsl dist

#all should be the first target. it's built when make is run without args
all: clean control ${OBJECTS}

#additional rules for files
${NAME}.elf: utils ${OBJECTS}
	${CC} -mmcu=${CPU} -o $@ ${OBJECTS} ${DEPS}

control:
	@(cd $(CTRL_DIR) && $(MAKE));

${NAME}.a43: ${NAME}.elf
	msp430-objcopy -O ihex $^ $@

${NAME}.lst: ${NAME}.elf
	msp430-objdump -dSt $^ >$@

${NAME}.dmp: ${NAME}.elf
	msp430-objdump -d $^ >$@

.s: .c
	${CC} -S $(CFLAGS) $^ >$@

download-jtag: all
	msp430-jtag -e ${NAME}.elf

download-bsl: all
	msp430-bsl -e ${NAME}.elf

clean:
	@(cd $(control) && $(MAKE) clean); \
	rm -f ${NAME}.elf ${NAME}.a43 ${NAME}.lst ${OBJECTS} wsim-* *~

#backup archive
dist:
	tar czf LCD.tgz *.c *.h  Makefile

#dummy target as dependecy if something has to be build everytime
FORCE:

#project dependencies
mode_freq.c: ../control/ctrl_freq.h


mode_vol.c: ../control/ctrl_vol.h


mode_station.c: ../control/ctrl_station.h


.o: ../utils/utils.h .c

